﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace GroupChallengeWP7.Views
{
    public partial class JoinView : UserControl
    {
        public JoinView()
        {
            InitializeComponent();
        }

        #region Join and Leave the Game

        private void JoinButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                App.ViewModel.JoinGame();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Unable to join the game.  Reason: " + ex.Message, "Join Game Error", MessageBoxButton.OK);
            }
        }

        private void LeaveButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                App.ViewModel.LeaveGame();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to leave the game.  Reason: " + ex.Message, "Leave Game Error", MessageBoxButton.OK);
            }
        }
        #endregion                              // Join and Leave the Game

        private void TextChanged(object sender, TextChangedEventArgs e)
        {
            ((TextBox)sender).GetBindingExpression(TextBox.TextProperty).UpdateSource();
        }
    }
}
